package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllTasks", query = "select myTask from Task myTask"),
		@NamedQuery(name = "findTaskByAdjustedEstimate", query = "select myTask from Task myTask where myTask.adjustedEstimate = ?1"),
		@NamedQuery(name = "findTaskByCreatedDate", query = "select myTask from Task myTask where myTask.createdDate = ?1"),
		@NamedQuery(name = "findTaskByDescription", query = "select myTask from Task myTask where myTask.description = ?1"),
		@NamedQuery(name = "findTaskByDueDate", query = "select myTask from Task myTask where myTask.dueDate = ?1"),
		@NamedQuery(name = "findTaskById", query = "select myTask from Task myTask where myTask.id = ?1"),
		@NamedQuery(name = "findTaskByOriginalEstimate", query = "select myTask from Task myTask where myTask.originalEstimate = ?1"),
		@NamedQuery(name = "findTaskByPrimaryKey", query = "select myTask from Task myTask where myTask.id = ?1"),
		@NamedQuery(name = "findTaskByTitle", query = "select myTask from Task myTask where myTask.title = ?1"),
		@NamedQuery(name = "findTaskByTitleContaining", query = "select myTask from Task myTask where myTask.title like ?1"),
		@NamedQuery(name = "findTaskByUpdatedDate", query = "select myTask from Task myTask where myTask.updatedDate = ?1") })
@Table(catalog = "sow", name = "task")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "Task")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class Task implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "TITLE", length = 200, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String title;
	/**
	 */

	@Column(name = "DESCRIPTION", columnDefinition = "TEXT")
	@Basic(fetch = FetchType.EAGER)
	@Lob
	@XmlElement
	String description;
	/**
	 */

	@Column(name = "ORIGINAL_ESTIMATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer originalEstimate;
	/**
	 */

	@Column(name = "ADJUSTED_ESTIMATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer adjustedEstimate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DUE_DATE", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar dueDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar createdDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar updatedDate;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByCreatedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PROJECT_ID", referencedColumnName = "ID") })
	@XmlTransient
	Project project;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "UPDATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByUpdatedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "ASSIGNED_TO", referencedColumnName = "ID") })
	@XmlTransient
	User userByAssignedTo;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "TASK_STATUS_ID", referencedColumnName = "ID") })
	@XmlTransient
	TaskStatus taskStatus;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "CATEGORY_ID", referencedColumnName = "ID") })
	@XmlTransient
	TaskCategory taskCategory;
	/**
	 */
	@OneToMany(mappedBy = "task", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.TaskComment> taskComments;
	/**
	 */
	@OneToMany(mappedBy = "task", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.TaskWorkLog> taskWorkLogs;
	/**
	 */
	@OneToMany(mappedBy = "task", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.TaskAttachment> taskAttachments;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 */
	public String getTitle() {
		return this.title;
	}

	/**
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 */
	public void setOriginalEstimate(Integer originalEstimate) {
		this.originalEstimate = originalEstimate;
	}

	/**
	 */
	public Integer getOriginalEstimate() {
		return this.originalEstimate;
	}

	/**
	 */
	public void setAdjustedEstimate(Integer adjustedEstimate) {
		this.adjustedEstimate = adjustedEstimate;
	}

	/**
	 */
	public Integer getAdjustedEstimate() {
		return this.adjustedEstimate;
	}

	/**
	 */
	public void setDueDate(Calendar dueDate) {
		this.dueDate = dueDate;
	}

	/**
	 */
	public Calendar getDueDate() {
		return this.dueDate;
	}

	/**
	 */
	public void setCreatedDate(Calendar createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 */
	public Calendar getCreatedDate() {
		return this.createdDate;
	}

	/**
	 */
	public void setUpdatedDate(Calendar updatedDate) {
		this.updatedDate = updatedDate;
	}

	/**
	 */
	public Calendar getUpdatedDate() {
		return this.updatedDate;
	}

	/**
	 */
	public void setUserByCreatedBy(User userByCreatedBy) {
		this.userByCreatedBy = userByCreatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByCreatedBy() {
		return userByCreatedBy;
	}

	/**
	 */
	public void setProject(Project project) {
		this.project = project;
	}

	/**
	 */
	@JsonIgnore
	public Project getProject() {
		return project;
	}

	/**
	 */
	public void setUserByUpdatedBy(User userByUpdatedBy) {
		this.userByUpdatedBy = userByUpdatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByUpdatedBy() {
		return userByUpdatedBy;
	}

	/**
	 */
	public void setUserByAssignedTo(User userByAssignedTo) {
		this.userByAssignedTo = userByAssignedTo;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByAssignedTo() {
		return userByAssignedTo;
	}

	/**
	 */
	public void setTaskStatus(TaskStatus taskStatus) {
		this.taskStatus = taskStatus;
	}

	/**
	 */
	@JsonIgnore
	public TaskStatus getTaskStatus() {
		return taskStatus;
	}

	/**
	 */
	public void setTaskCategory(TaskCategory taskCategory) {
		this.taskCategory = taskCategory;
	}

	/**
	 */
	@JsonIgnore
	public TaskCategory getTaskCategory() {
		return taskCategory;
	}

	/**
	 */
	public void setTaskComments(Set<TaskComment> taskComments) {
		this.taskComments = taskComments;
	}

	/**
	 */
	@JsonIgnore
	public Set<TaskComment> getTaskComments() {
		if (taskComments == null) {
			taskComments = new java.util.LinkedHashSet<edu.hcmus.sow.domain.TaskComment>();
		}
		return taskComments;
	}

	/**
	 */
	public void setTaskWorkLogs(Set<TaskWorkLog> taskWorkLogs) {
		this.taskWorkLogs = taskWorkLogs;
	}

	/**
	 */
	@JsonIgnore
	public Set<TaskWorkLog> getTaskWorkLogs() {
		if (taskWorkLogs == null) {
			taskWorkLogs = new java.util.LinkedHashSet<edu.hcmus.sow.domain.TaskWorkLog>();
		}
		return taskWorkLogs;
	}

	/**
	 */
	public void setTaskAttachments(Set<TaskAttachment> taskAttachments) {
		this.taskAttachments = taskAttachments;
	}

	/**
	 */
	@JsonIgnore
	public Set<TaskAttachment> getTaskAttachments() {
		if (taskAttachments == null) {
			taskAttachments = new java.util.LinkedHashSet<edu.hcmus.sow.domain.TaskAttachment>();
		}
		return taskAttachments;
	}

	/**
	 */
	public Task() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Task that) {
		setId(that.getId());
		setTitle(that.getTitle());
		setDescription(that.getDescription());
		setOriginalEstimate(that.getOriginalEstimate());
		setAdjustedEstimate(that.getAdjustedEstimate());
		setDueDate(that.getDueDate());
		setCreatedDate(that.getCreatedDate());
		setUpdatedDate(that.getUpdatedDate());
		setUserByCreatedBy(that.getUserByCreatedBy());
		setProject(that.getProject());
		setUserByUpdatedBy(that.getUserByUpdatedBy());
		setUserByAssignedTo(that.getUserByAssignedTo());
		setTaskStatus(that.getTaskStatus());
		setTaskCategory(that.getTaskCategory());
		setTaskComments(new java.util.LinkedHashSet<edu.hcmus.sow.domain.TaskComment>(that.getTaskComments()));
		setTaskWorkLogs(new java.util.LinkedHashSet<edu.hcmus.sow.domain.TaskWorkLog>(that.getTaskWorkLogs()));
		setTaskAttachments(new java.util.LinkedHashSet<edu.hcmus.sow.domain.TaskAttachment>(that.getTaskAttachments()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("title=[").append(title).append("] ");
		buffer.append("description=[").append(description).append("] ");
		buffer.append("originalEstimate=[").append(originalEstimate).append("] ");
		buffer.append("adjustedEstimate=[").append(adjustedEstimate).append("] ");
		buffer.append("dueDate=[").append(dueDate).append("] ");
		buffer.append("createdDate=[").append(createdDate).append("] ");
		buffer.append("updatedDate=[").append(updatedDate).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Task))
			return false;
		Task equalCheck = (Task) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
